#! /bin/bash

if [ $# == 0 ] ; then
	
   echo "这样使用：./deploy.sh earth"

   echo "使用方法："
   
   echo "./deploy.sh earth  ==>发布earth系统"
   echo "./deploy.sh deduct  ==>发布bridgewater-deduct系统"
   echo "./deploy.sh munichre  ==>发布munichre系统"
   echo "./deploy.sh swissre  ==>发布swissre系统"
   echo "./deploy.sh deloitte  ==>发布deloitte系统"
   echo "./deploy.sh morganStanley ==>发布morganStanley系统"
   echo "./deploy.sh citigroup ==>发布citigroup系统"
   echo "./deploy.sh jpmorgan ==>发布jpmorgan系统"
   echo "./deploy.sh remittance ==>发布remittance系统"
   echo "./deploy.sh barclays ==>发布barclays系统"
   echo "./deploy.sh sign ==>发布sign系统"
exit

fi


PROJECT_BASE=/data/repos

cd $PROJECT_BASE/zufangbao-springboot-center

bash package.sh

if [ $1 == "consumer" ] ; then

  project="berkshire";

elif [  $1 == "producer" ]; then

  project="PriceWaterHouse" ;

elif [ $1 == "deduct" ] ; then

 project="bridgewater-deduct"

elif  [ $1 == "swissre" ] ; then

 project="SwissRe"

elif [ $1 == "munichre" ]; then

 project="MunichRe"

elif [ $1 == "deloitte" ]; then
 project="Deloitte"

elif [ $1 == "morganStanley" ]; then
 project="morganStanley"

elif [ $1 == "jpmorgan" ]; then
 project="jpmorgan"

elif [ $1 == "remittance" ]; then
 project="bridgewater-remittance"

elif [ $1 == "barclays" ]; then
 project="Barclays"
elif [ $1 == "sign" ]; then
 project="sign"
else
   project=$1

fi




if [ $1 == "consumer" ] || [ $1 == "producer" ]; then

if [ $1 == "consumer"  ]; then

     id_rsa_suffix="207"
     ip="192.168.0.207"

  else
     id_rsa_suffix="206"
     ip="192.168.0.206"
  fi

  scp -i ~/.ssh/id_rsa_60.190.243.68_22  $PROJECT_BASE/$project/target/$project-1.0.0-SNAPSHOT.jar root@$ip:/opt

  sh /data/scripts/myscripts/start_stop.sh start $1

fi


if [ $1 == "earth" ] || [ $1 == "deduct" ] || [ $1 == "jpmorgan" ] || [ $1 == "remittance" ] || [ $1 == "barclays" ]; then
  
       rm -rf /data/webapps/tomcat-$1/webapps/$1
     if [ $1 == "deduct" ] || [ $1 == "jpmorgan" ] || [ $1 == "remittance" ] || [ $1 == "earth" ]; then
        unzip /data/repos/$project/target/$project-1.0.0-SNAPSHOT.war -d /data/webapps/tomcat-$1/webapps/$1
     elif [ $1 == "barclays" ]; then
        unzip /data/repos/$project/target/$1-1.0.0-SNAPSHOT.war -d /data/webapps/tomcat-$1/webapps/$1
      fi   

       sh /data/scripts/myscripts/override_config.sh $1
       sh /data/scripts/myscripts/start_stop.sh stop $1
       sh /data/scripts/myscripts/start_stop.sh start $1

fi

if [ $1 == "sign" ] ||  [ $1 == "swissre" ] || [ $1 == "munichre" ] || [ $1 == "morganStanley" ] || [ $1 == "citigroup" ]; then
echo "已进入$1"   
rm -rf /data/webapps/$1/$1-1.0.0-SNAPSHOT.jar
   cp -f /data/repos/$project/target/$1-1.0.0-SNAPSHOT.jar /data/webapps/$1/

     sh /data/scripts/myscripts/start_stop.sh stop $1
     sh /data/scripts/myscripts/start_stop.sh start $1
      echo "已经成功开启$project"
fi
